package com.sc.VenusQueryBeta.adapter.home;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.sc.VenusQueryBeta.R;
import com.sc.VenusQueryBeta.api.Host;
import com.sc.VenusQueryBeta.model.bean.home.VipListBean;

/**
 * Created by Administrator on 21/9/2018.
 *
 */

public class GridViewAdapter extends BaseAdapter {
    private VipListBean vipListBean;
    private Context context;

    public  GridViewAdapter(Context context, VipListBean vipListBean) {
        this.context = context;
        this.vipListBean = vipListBean;
    }

    @Override
    public int getCount() {
        return vipListBean.getData().get(0).getClubList().size();
    }

    @Override
    public Object getItem(int position) {
        return vipListBean.getData().get(0).getClubList().get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
     final    ViewHolder viewHolder;
        if (convertView == null){
            convertView = View.inflate(context, R.layout.item_gv_channel,null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
                if (vipListBean.getData().size()>0&&vipListBean.getData().get(0).getClubList().size()>0) {
                    Glide.with(context).load(Host.HostImg+vipListBean.getData().get(0).getClubList().get(position).getClubLogoUrl()).into(viewHolder.ivChannel);
                }
            convertView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (vipListBean.getData().size()>0&&vipListBean.getData().get(0).getClubList().size()>0) {
                        VipListBean.DataBean.ClubListBean clubListBean = vipListBean.getData().get(0).getClubList().get(position);

                        clickListener.click(clubListBean,position);
                    }
                }
            });
        }
        else {
            viewHolder= (ViewHolder) convertView.getTag();
        }

        return convertView;
    }


    class ViewHolder{
         ImageView ivChannel;
         ViewHolder(View convertView) {
            ivChannel = convertView.findViewById(R.id.iv_channel);
        }

    }
    public interface ClickListener{
        void click(VipListBean.DataBean.ClubListBean clubListBean, int position);
    }

    public void setClickListener(ClickListener clickListener) {
        this.clickListener = clickListener;
    }

    ClickListener clickListener;
}
